# Maintainer: AlexWMF <alexxwmf@gmail.com>

_realname=libvmime
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r1243.f5fa6434
_commit=f5fa6434aa3ad64988e85323dff7eb13d4829d0f
pkgrel=1
pkgdesc="An open source solution for working with MIME messages and Internet messaging services like IMAP, POP or SMTP (mingw-w64)"
url="https://www.vmime.org/"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('GPL3')
options=('strip' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-icu"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gsasl"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         #"${MINGW_PACKAGE_PREFIX}-openssl"
        )
source=("${_realname}"::"git+https://github.com/kisli/vmime.git#commit=$_commit"
        cmake_mlang.patch)
sha256sums=('SKIP'
            '24af4dc260c5a2b9f06635a7dec232687062b1940b4c3747fd7a81f383f4a83d')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${_realname}"
  patch -p1 -i ${srcdir}/cmake_mlang.patch
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  if check_option "debug" "y"; then
    _build_type="Debug"
  else
    _build_type="Release"
  fi

  LDFLAGS+=" -Wl,--export-all-symbols"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=${_build_type} \
    -DVMIME_HAVE_MESSAGING_PROTO_SENDMAIL=OFF \
    -DVMIME_BUILD_SAMPLES=OFF \
    -DVMIME_TLS_SUPPORT_LIB=gnutls \
    ../${_realname}

  cmake --build .
}

package() {
  cd build-${MSYSTEM}
  DESTDIR=${pkgdir} cmake --install .
}
